home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / appsrcs.zip / MORSETUP.ZIP / APPINI.C < prev    next >
C/C++ Source or Header  |  1993-06-04  |  10KB  |  255 lines

  1. #define STRICT
  2. #include <windows.h>
  3. #include <windowsx.h>
  4. #include <shellapi.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include "morsetup.h"
  9.  
  10. char WindowsDir[MAXFILECHARS];
  11. int temp;
  12.  
  13. #define WITHIN(val, min, max)      (((temp=val) > max ? max : (temp < min) ? min : temp))
  14. #define ONEORZERO(val)          WITHIN((BOOL)val, 0, 1)
  15.  
  16. /*--------------------------------------------------------------------------*/
  17. /* FUNCTION: IniRead(void)                            */
  18. /*                                        */
  19. /* PURPOSE:  Read settings in the appbar.ini file.                */
  20. /*--------------------------------------------------------------------------*/
  21. VOID PASCAL IniRead(VOID)
  22.     {
  23.     char ReadString[MAXDIGITS],IniString[20];
  24.     char SystemSection[256], ButtonSection[256], SoundSection[256];
  25.     int i, itemp;
  26.  
  27.     SetCursor(LoadCursor(NULL, IDC_WAIT));
  28.  
  29.     if(AppSystem.SectionNumber == 0)
  30.     {
  31.     for(i=0;i<MAXAPPS;i++)
  32.         AppButton[i] = AppButtonDefault;
  33.     strcpy(AppSystem.SectionName, "<none>");
  34.     SetCursor(LoadCursor(NULL, IDC_ARROW));
  35.     return;
  36.     }
  37.  
  38.     sprintf(IniString,"%d", AppSystem.SectionNumber);
  39.     GetPrivateProfileString(INI_APPMORE, IniString, SECTIONNAME_DEFAULT,
  40.                 AppSystem.SectionName, MAXFILECHARS-1, INI_FILE);
  41.  
  42.     // get ini-settings for AppSystem struct.
  43.     strcpy(SystemSection, AppSystem.SectionName);
  44.     strcat(SystemSection, "_System");
  45.     strcpy(ButtonSection, AppSystem.SectionName);
  46.     strcat(ButtonSection, "_Buttons");
  47.     strcpy(SoundSection, AppSystem.SectionName);
  48.     strcat(SoundSection, "_Sounds");
  49.  
  50.     for(i=0;i<MAXAPPS;i++)
  51.     {
  52.     bSaveButton[i] = FALSE;
  53.     AppButton[i] = ReadButtonIni(i, (LPSTR)ButtonSection, (LPSTR) INI_FILE);
  54.     }
  55.  
  56.     // get ini-settings for AppSystem struct.
  57.     itemp = GetPrivateProfileInt(SystemSection, LEFT, LEFT_DEFAULT, INI_FILE);
  58.     AppSystem.Left = WITHIN(itemp, -1, MAXRES);
  59.  
  60.     itemp = GetPrivateProfileInt(SystemSection, TOP, TOP_DEFAULT, INI_FILE);
  61.     AppSystem.Top = WITHIN(itemp, -1, MAXRES);
  62.  
  63.     itemp = GetPrivateProfileInt(SystemSection, CLOSEALL, CLOSEALL_DEFAULT, INI_FILE);
  64.     AppSystem.CloseAll = ONEORZERO(itemp);
  65.  
  66.     itemp = GetPrivateProfileInt(SystemSection, STAYINFRONT, STAYINFRONT_DEFAULT, INI_FILE);
  67.     AppSystem.StayInFront = ONEORZERO(itemp);
  68.  
  69.     itemp = GetPrivateProfileInt(SystemSection, DOUBLECLICK, DOUBLECLICK_DEFAULT, INI_FILE);
  70.     AppSystem.DoubleClick = ONEORZERO(itemp);
  71.  
  72.     itemp = GetPrivateProfileInt(SystemSection, BIGBUTTONS, BIGBUTTONS_DEFAULT, INI_FILE);
  73.     AppSystem.BigButtons = ONEORZERO(itemp);
  74.  
  75.     itemp = GetPrivateProfileInt(SystemSection, INITIALIZED, INITIALIZED_DEFAULT, INI_FILE);
  76.     AppSystem.Initialized = WITHIN(itemp, 0, APPMOREVERSION);
  77.  
  78.     itemp = GetPrivateProfileInt(SystemSection, BUTTONS, BUTTONS_DEFAULT, INI_FILE);
  79.     AppSystem.Buttons = WITHIN(itemp, 1, MAXAPPS);
  80.  
  81.     itemp = GetPrivateProfileInt(SystemSection, COLUMNS, COLUMNS_DEFAULT, INI_FILE);
  82.     AppSystem.Columns = WITHIN(itemp, 1, AppSystem.Buttons+1);
  83.  
  84.     itemp = GetPrivateProfileInt(SystemSection, BORDER, BORDER_DEFAULT, INI_FILE);
  85.     AppSystem.Border = WITHIN(itemp, 0, MAXBORDER);
  86.  
  87.     GetPrivateProfileString(SystemSection, DEFAULTICONDIR, AppSystem.DefaultIconDir,
  88.                AppSystem.DefaultIconDir, MAXFILECHARS-1, INI_FILE);
  89.  
  90.     itemp = GetPrivateProfileInt(SystemSection, ONELAUNCH, ONELAUNCH_DEFAULT, INI_FILE);
  91.     AppSystem.OneLaunch = WITHIN(itemp, 0, MAXBORDER);
  92.  
  93.     GetPrivateProfileString(SoundSection, SOUNDENABLE, SOUNDENABLE_DEFAULT,
  94.             ReadString, MAXDIGITS, INI_FILE);
  95.     AppSound.EnableSound = atoi(ReadString);
  96.     AppSound.EnableSound = max(AppSound.EnableSound, 0);
  97.     AppSound.EnableSound = min(AppSound.EnableSound, 1);
  98.  
  99.     GetPrivateProfileString(SoundSection, PROGSTART, PROGSTART_DEFAULT,
  100.         AppSound.ProgramStart, MAXFILECHARS-1, INI_FILE);
  101.  
  102.     GetPrivateProfileString(SoundSection, PROGCLOSE, PROGCLOSE_DEFAULT,
  103.         AppSound.ProgramClose, MAXFILECHARS-1, INI_FILE);
  104.  
  105.     GetPrivateProfileString(SoundSection, DROPFILE, DROPFILE_DEFAULT,
  106.         AppSound.DropFile, MAXFILECHARS-1, INI_FILE);
  107.  
  108.     GetPrivateProfileString(SoundSection, ERRORMESSAGE, ERRORMESSAGE_DEFAULT,
  109.         AppSound.ErrorMessage, MAXFILECHARS-1, INI_FILE);
  110.  
  111.     SetCursor(LoadCursor(NULL, IDC_ARROW));
  112.     }
  113.  
  114. /*--------------------------------------------------------------------------*/
  115. /* FUNCTION: IniSave(void)                            */
  116. /*                                        */
  117. /* PURPOSE:  Saves settings to the appbar.ini file.                */
  118. /*--------------------------------------------------------------------------*/
  119. VOID PASCAL IniSave(VOID)
  120.     {
  121.     char SaveString[MAXDIGITS],IniString[20];
  122.     int i;
  123.     char SystemSection[256], ButtonSection[256], SoundSection[256];
  124.  
  125.     SetCursor(LoadCursor(NULL, IDC_WAIT));
  126.  
  127.     // get ini-settings for AppSystem struct.
  128.     strcpy(SystemSection, AppSystem.SectionName);
  129.     strcat(SystemSection, "_System");
  130.     strcpy(ButtonSection, AppSystem.SectionName);
  131.     strcat(ButtonSection, "_Buttons");
  132.     strcpy(SoundSection, AppSystem.SectionName);
  133.     strcat(SoundSection, "_Sounds");
  134.  
  135.     // Save ini-settings from AppButton struct.
  136.     for(i=0;i<MAXAPPS;i++)
  137.         SaveButtonIni(AppButton[i], i, (LPSTR)ButtonSection, (LPSTR) INI_FILE);
  138.  
  139.     // Save ini-settings from AppSystem struct.
  140.     sprintf(SaveString,"%d",AppSystem.Left);
  141.     WritePrivateProfileString(SystemSection, LEFT, SaveString, INI_FILE);
  142.     sprintf(SaveString,"%d",AppSystem.Top);
  143.     WritePrivateProfileString(SystemSection, TOP, SaveString, INI_FILE);
  144.     sprintf(SaveString,"%d",AppSystem.Columns);
  145.     WritePrivateProfileString(SystemSection, COLUMNS, SaveString, INI_FILE);
  146.     sprintf(SaveString,"%d",AppSystem.Buttons);
  147.     WritePrivateProfileString(SystemSection, BUTTONS, SaveString, INI_FILE);
  148.     sprintf(SaveString,"%d",AppSystem.OneLaunch);
  149.     WritePrivateProfileString(SystemSection, ONELAUNCH, SaveString, INI_FILE);
  150.     sprintf(SaveString,"%d",AppSystem.CloseAll);
  151.     WritePrivateProfileString(SystemSection, CLOSEALL, SaveString, INI_FILE);
  152.     sprintf(SaveString,"%d",AppSystem.StayInFront);
  153.     WritePrivateProfileString(SystemSection, STAYINFRONT, SaveString, INI_FILE);
  154.     sprintf(SaveString,"%d",AppSystem.DoubleClick);
  155.     WritePrivateProfileString(SystemSection, DOUBLECLICK, SaveString, INI_FILE);
  156.     sprintf(SaveString,"%d",AppSystem.BigButtons);
  157.     WritePrivateProfileString(SystemSection, BIGBUTTONS, SaveString, INI_FILE);
  158.     sprintf(SaveString,"%d",AppSystem.Border);
  159.     WritePrivateProfileString(SystemSection, BORDER, SaveString, INI_FILE);
  160.  
  161.     // Save AppSound settings.
  162.     sprintf(SaveString,"%d",AppSound.EnableSound);
  163.     WritePrivateProfileString(SoundSection, SOUNDENABLE, SaveString, INI_FILE);
  164.     WritePrivateProfileString(SoundSection, PROGSTART, AppSound.ProgramStart, INI_FILE);
  165.     WritePrivateProfileString(SoundSection, PROGCLOSE, AppSound.ProgramClose, INI_FILE);
  166.     WritePrivateProfileString(SoundSection, DROPFILE, AppSound.DropFile, INI_FILE);
  167.     WritePrivateProfileString(SoundSection, ERRORMESSAGE, AppSound.ErrorMessage, INI_FILE);
  168.     WritePrivateProfileString(INI_APPMORE, SOUNDDIR, AppSound.SoundDirectory, INI_FILE);
  169.     SetCursor(LoadCursor(NULL, IDC_ARROW));
  170.     }
  171.  
  172. /*------------------------------------------------------------------------*/
  173. int VerifySectionName(LPSTR SectionName)
  174.     {
  175.     int i;
  176.     char IniString[20];
  177.  
  178.     GetPrivateProfileString(INI_APPMORE, NUMBEROFSECTIONS, SECTIONS_DEFAULT,
  179.                 szBuffer, MAXDIGITS, INI_FILE);
  180.     AppSystem.NumberOfSections = atoi(szBuffer);
  181.     AppSystem.NumberOfSections = max(AppSystem.NumberOfSections, 0);
  182.  
  183.     if(AppSystem.NumberOfSections == 0)
  184.     return 0;
  185.  
  186.     for(i=0;i<AppSystem.NumberOfSections;i++)
  187.     {
  188.     sprintf(IniString,"%d",i+1);
  189.     GetPrivateProfileString(INI_APPMORE, IniString, SECTIONNAME_DEFAULT,
  190.                 szBuffer, MAXFILECHARS-1, INI_FILE);
  191.     if(strcmp(szBuffer,SectionName) == 0)
  192.         return (i+1);
  193.     }
  194.     return 0;
  195.     }
  196.  
  197. /*-------------------------------------------------------------------------*/
  198. VOID AddSectionName(LPSTR NewSectionName)
  199.     {
  200.     char IniString[20];
  201.  
  202.     AppSystem.NumberOfSections++;
  203.     sprintf(IniString,"%d",AppSystem.NumberOfSections);
  204.     WritePrivateProfileString(INI_APPMORE, IniString, NewSectionName, INI_FILE);
  205.     WritePrivateProfileString(INI_APPMORE, NUMBEROFSECTIONS, IniString, INI_FILE);
  206.     }
  207.  
  208. /*-------------------------------------------------------------------------*/
  209. VOID DeleteSectionName(LPSTR OldSectionName)
  210.     {
  211.     char IniString[20];
  212.     int SectionNumber, i;
  213.  
  214.     SectionNumber = VerifySectionName(OldSectionName);
  215.     for(i=SectionNumber;i<AppSystem.NumberOfSections;i++)
  216.     {
  217.     sprintf(IniString,"%d",i+1);
  218.     GetPrivateProfileString(INI_APPMORE, IniString, SECTIONNAME_DEFAULT,
  219.                 szBuffer, MAXFILECHARS-1, INI_FILE);
  220.     sprintf(IniString,"%d",i);
  221.     WritePrivateProfileString(INI_APPMORE, IniString, szBuffer, INI_FILE);
  222.     }
  223.     AppSystem.NumberOfSections--;
  224.     sprintf(IniString,"%d",AppSystem.NumberOfSections);
  225.     WritePrivateProfileString(INI_APPMORE, NUMBEROFSECTIONS, IniString, INI_FILE);
  226.     }
  227.  
  228. /*--------------------------------------------------------------------------*/
  229. VOID InitDefaultButton(VOID)
  230.     {
  231.     char ReadString[MAXDIGITS];
  232.  
  233.     GetWindowsDirectory(WindowsDir, MAXFILECHARS);
  234.  
  235.     AppButtonDefault = InitButton();
  236.  
  237.     AppSound.EnableSound = 0;
  238.     strcpy(AppSound.ProgramStart, PROGSTART_DEFAULT);
  239.     strcpy(AppSound.ProgramClose, PROGCLOSE_DEFAULT);
  240.     strcpy(AppSound.DropFile, DROPFILE_DEFAULT);
  241.     strcpy(AppSound.ErrorMessage, ERRORMESSAGE_DEFAULT);
  242.  
  243.     GetPrivateProfileString(INI_APPMORE, INITIALIZED, INITIALIZED_DEFAULT,
  244.                 ReadString, MAXDIGITS, INI_FILE);
  245.     AppSystem.Initialized = atoi(ReadString);
  246.     AppSystem.Initialized = max(AppSystem.Initialized, 0);
  247.  
  248.     strcpy(AppSystem.DefaultIconDir,"");
  249.     GetPrivateProfileString(INI_APPMORE, DEFAULTICONDIR, AppSystem.DefaultIconDir,
  250.         AppSystem.DefaultIconDir, MAXFILECHARS-1, INI_FILE);
  251.  
  252.     GetPrivateProfileString(INI_APPMORE, SOUNDDIR, WindowsDir,
  253.         AppSound.SoundDirectory, MAXFILECHARS-1, INI_FILE);
  254.     }
  255.